//
//  LGMineViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/16.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "TGPointChangeViewController.h"
@interface TGPointChangeViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@property(nonatomic, strong) UITextField     *textFiled;
@end

@implementation TGPointChangeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"积分兑换";
    [self configSubViewWithUserModel:nil];
    [self configDataSouce];
    [self configTableFooter];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubViewWithUserModel:(LGUserModel*)userModel{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 120)];
    header.backgroundColor = [UIColor whiteColor];
    
    STButton * imageButton = [[STButton alloc] initWithFrame:CGRectMake(20, 20, UIScreenWidth - 40, 120)
                                                       title:nil
                                                  titleColor:nil
                                                   titleFont:0
                                                cornerRadius:4
                                             backgroundColor:nil
                                             backgroundImage:[UIImage imageNamed:@"2"]
                                                       image:nil];
    imageButton.centerX = header.width / 2;
    imageButton.userInteractionEnabled = NO;
    imageButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:imageButton];
    

    header.height = imageButton.bottom + 30;
    self.tableView.tableHeaderView = header;
    
}
- (void)configDataSouce{
    self.textFiled = [self defultTextFiled];
    STTableEasyModel * model0 = [[STTableEasyModel alloc] initWithTextString:@"兑换积分"
                                                                accessoryView:self.textFiled];
    STTableEasyModel * model1 = [[STTableEasyModel alloc] initWithTextString:@"转换礼根币"
                                                                detailString:@"礼根币"];
    NSArray * sectionOne = @[model0,model1];

    
    self.dataSouce = @[sectionOne];
    [self.tableView reloadData];
}
- (UITextField*)defultTextFiled{
    UITextField * textFild = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    textFild.placeholder = @"请输入10的整数倍";
    textFild.textAlignment = NSTextAlignmentRight;
    textFild.keyboardType = UIKeyboardTypeNumberPad;
    return textFild;
}
- (void)configTableFooter{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(self.insetX,0, 200, 44)
                                                   text:@"积分礼根币兑换比率为10:1"
                                               textColor:TM_redColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [footer addSubview:desLable];
    
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30 , 44)
                                                        title:@"确认兑换"
                                                   titleColor:FlatWhite
                                                    titleFont:18
                                                 cornerRadius:6
                                              backgroundColor:TM_redColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedChangeButton];
    }];
    confimButton.top = 50;
    [confimButton st_showTopLine];
    [confimButton st_showBottomLine];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    footer.height = confimButton.bottom;
    self.tableView.tableFooterView = footer;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.dataSouce[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 49;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedChangeButton{

}

@end


